package com.woniu.service.impl;

import com.woniu.dao.ClientDao;
import com.woniu.dao.OverdueManagementDao;
import com.woniu.entity.OverdueManagement;
import com.woniu.service.OverdueManagementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

import static com.ruoyi.common.utils.DateUtils.differentDaysByMillisecond;
import static com.ruoyi.common.utils.DateUtils.getNowDate;

@Service
public class OverdueManagementServiceImpl implements OverdueManagementService {
//    @Resource
//    @Qualifier("overdueManagement")
    @Autowired
    OverdueManagementDao overdueManagementDao;

    @Override
    public List<OverdueManagement> findAll(OverdueManagement overdueManagement) {
        List<OverdueManagement> all = overdueManagementDao.findAll(overdueManagement);
        //System.out.println(all);
        for (OverdueManagement management : all) {
            if(management.getCreditTime()!=null){
                management.setPrincipalName(overdueManagementDao.findprincipalName(management.getPrincipalId()));
                if((differentDaysByMillisecond(management.getCreditTime(),getNowDate())-(management.getPeriods()*30))>=0){
                    overdueManagementDao.setApplicantStatus(management.getLoanId());
                    management.setOverdueDateNum(differentDaysByMillisecond(management.getCreditTime(),getNowDate())-management.getPeriods()*30);
                    overdueManagementDao.setOverdueDateNum(management.getLoanId(),management.getOverdueDateNum());
                }
            }
        }
        return all;
    }

    @Override
    public void updateOverdueManagement(int[] id) {
        for (int i=0;i<id.length;i++){
            overdueManagementDao.updateOverdueManagement(id[i]);
        }
    }

    @Override
    public List<OverdueManagement> exportOverdueList() {
        return overdueManagementDao.exportOverdueList();
    }
}
